package top.conangao.common.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @author ConanGao
 * @since 1.0
 **/
@AllArgsConstructor
@NoArgsConstructor
@Data
public final class ResponseResult<T> implements Serializable {
    public static<T> ResponseResult<T> ok(){
        return new ResponseResult<>(ResponseResultEnum.SUCCESS);
    }

    public static<T> ResponseResult<T> ok(String message) {
        return new ResponseResult<T>(ResponseResultEnum.SUCCESS.getCode(),message,null);
    }

    public static<T> ResponseResult<T> ok(String message,T data) {
        return new ResponseResult<T>(ResponseResultEnum.SUCCESS.getCode(),message,data);
    }

    public static<T> ResponseResult<T> fail(){
        return new ResponseResult<>(ResponseResultEnum.ERROR);
    }

    public static<T> ResponseResult<T> fail(String message) {
        return new ResponseResult<>(ResponseResultEnum.ERROR.getCode(),message,null);}

    public static<T> ResponseResult<T> fail(String message,T data) {
        return new ResponseResult<>(ResponseResultEnum.ERROR.getCode(),message,data);
    }

    public ResponseResult(ResponseResultEnum responseEnum){
        this.code = responseEnum.getCode();
        this.message = responseEnum.getMessage();
    }

    private Integer code;
    private String message;
    private T data;
}
